package com.hongyi.common.saToken.service;

import cn.dev33.satoken.stp.StpInterface;
import com.hongyi.common.framework.domain.LoginUser;
import com.hongyi.common.framework.utils.StreamUtils;
import com.hongyi.common.saToken.utils.LoginUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * sa-token 权限管理实现类
 *
 * @author DingHao
 */
public class SaPermissionImpl implements StpInterface {

    /**
     * 获取菜单权限列表
     */
    @Override
    public List<String> getPermissionList(Object o, String s) {
        LoginUser loginUser = LoginUtils.getLoginUser();
        Set<String> menuPermissions = loginUser.getMenuPermission();
        return StreamUtils.toList(menuPermissions,menuPermission->menuPermission);
    }

    /**
     * 获取角色权限列表
     */
    @Override
    public List<String> getRoleList(Object o, String s) {
        LoginUser loginUser = LoginUtils.getLoginUser();
        Set<String> rolePermissions = loginUser.getRolePermission();
        return StreamUtils.toList(rolePermissions, rolePermission -> rolePermission);

    }
}
